<template>
  <div class="products-container">
    <h1>产品中心</h1>

    <!-- 产品快速索引区 -->
    <div class="product-index">
      <h2>产品快速索引</h2>
      <div class="index-grid">
        <div v-for="product in products" :key="product.id" class="index-item" @click="scrollToProduct(product.id)">
          <div class="index-icon">
            <img :src="product.icon" :alt="product.name">
          </div>
          <h3>{{ product.name }}</h3>
        </div>
      </div>
    </div>

    <!-- 产品详细介绍区 -->
    <div class="product-details">
      <div v-for="product in products" :key="product.id" :id="product.id" class="product-section">
        <h2>{{ product.name }}</h2>
        <div class="product-content">
          <!-- 多图展示 -->
          <div :class="`product-images-${product.column}`">
            <img v-for="(img, idx) in product.productImages" :key="idx" :src="img" :alt="`${product.name}-${idx + 1}`"
              class="product-image">
          </div>
          <br>
        </div>
        <div><b style="color:red">{{ product.name }}</b>{{ product.desc }}</div>
      </div>
    </div>
    
    <!-- 右下角浮动菜单 -->
    <div class="floating-menu" :class="{ 'collapsed': isMenuCollapsed }">
      <div class="menu-header" @click="isMenuCollapsed = !isMenuCollapsed">
        <span>产品导航</span>
        <span class="toggle-icon">{{ isMenuCollapsed ? '>' : 'v' }}</span>
      </div>
      <div class="menu-content" v-if="!isMenuCollapsed">
        <div 
          v-for="product in products" 
          :key="product.id" 
          class="menu-item"
          @click="scrollToProduct(product.id)">
          {{ product.name }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import product from "../js/products";

export default {
  name: 'Products',
  data() {
    return {
      isMenuCollapsed: true,  // 新增：控制菜单折叠状态
      products: product
    }
  },
  methods: {
    scrollToProduct(id) {
      const element = document.getElementById(id);
      if (element) {
        element.scrollIntoView({ behavior: 'smooth' });
      }
    }
  }
}
</script>

<style scoped>
.products-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

h1 {
  text-align: center;
  color: #2c3e50;
  margin-bottom: 40px;
}

/* 产品索引区样式 */
.product-index {
  margin-bottom: 50px;
  padding: 20px;
  background: #f5f7fa;
  border-radius: 8px;
}

.index-grid { display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.index-item {
  background: white;
  border-radius: 8px;
  padding: 15px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.index-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.index-icon img {
  width: 50px;
  height: 50px;
  object-fit: contain;
}

/* 产品详情区样式 */
.product-section {
  margin-bottom: 60px;
  padding-bottom: 30px;
  border-bottom: 1px solid #eee;
  display: flex;          /* 新增 */
  flex-direction: column; /* 新增 */
  align-items: center;    /* 新增 */
}

.product-content {
  display: flex;
  gap: 30px;
  margin-top: 20px;
  width: 100%;            /* 新增 */
  justify-content: center;/* 新增 */
}

.product-image {
  height: 240px;
  width: 250px;
  object-fit: cover;
  border-radius: 8px;
}

.product-info {
  flex: 1;
}

.specs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.spec-item {
  background: #f8f9fa;
  padding: 8px 12px;
  border-radius: 4px;
}

.spec-key {
  font-weight: bold;
  margin-right: 5px;
}
/* 新增多图展示样式 */
.product-images-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 300px;
  min-width: 300px;
  /* 保持与原单图宽度一致 */
}
/* 新增多图展示样式 */
.product-images-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 100px;
  min-width: 300px;
  /* 保持与原单图宽度一致 */
}
.product-images-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
  min-width: 300px;
  /* 保持与原单图宽度一致 */
}

.product-image {
  width: 256px;
  /* 适应网格布局 */
  height: 256px;
  /* 统一高度 */
  object-fit: cover;
  border-radius: 8px;
}

/* 新增浮动菜单样式 */
.floating-menu {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 200px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  transition: all 0.3s ease;
}

.menu-header {
  padding: 12px 15px;
  background: #1976d2;
  color: white;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.toggle-icon {
  font-weight: bold;
}

.menu-content {
  max-height: 400px;
  overflow-y: auto;
}

.menu-item {
  padding: 10px 15px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  transition: background 0.2s;
}

.menu-item:hover {
  background: #f5f7fa;
}

.menu-item:last-child {
  border-bottom: none;
}

.floating-menu.collapsed {
  width: 120px;
}

.floating-menu.collapsed .menu-header {
  border-radius: 8px;
}
</style>